package com.wenhui.schoolyardinfo.square.model;

import android.content.Context;

import com.wenhui.schoolyardinfo.login.callback.OnLoginListener;
import com.wenhui.schoolyardinfo.manager.Okhttp3Manager;
import com.wenhui.schoolyardinfo.square.callback.OnPublicGoodListener;
import com.wenhui.schoolyardinfo.square.callback.OnSquareListener;
import com.wenhui.schoolyardinfo.square.model.base.IPublicGoodModel;

import java.io.IOException;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * author    : mahongyin
 * e-mail    : 1976222027@qq.com
 * date      :2019/7/17 15:53
 * introduce :
 */

public class PublicGoodModelImpl implements IPublicGoodModel{
    private Context context;
    private Okhttp3Manager okhttp3Manager;
  public  PublicGoodModelImpl (Context context){
      this.context=context;
  }
    @Override
    public void getPublicGoodData(Map<String, String> bodyParams, final OnPublicGoodListener onPublicGoodListener) {
        okhttp3Manager = Okhttp3Manager.getInstance(context);
        okhttp3Manager.postAsyncFormOkhttp3("192.168.31.96:8080/",
                null,
                bodyParams,
                new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        onPublicGoodListener.onSquareError(e.toString());
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        onPublicGoodListener.onSquareSuccess(response.body().string());
                    }
                });
    }
}
